package com.jcl.core.web.model;

import com.jcl.core.utils.EncryptUtils;

/**
 * @ClassName CrawlerUserToken

 * @Author yyliu
 * @Date 2018/10/25 14:55
 * @Version 1.0
 **/
public class CrawlerUserToken {
    private static final String split = "_";
    private String corpCode;
    private String userId;
    private String resumeId;

    public static CrawlerUserToken decodeTenantId(String tenantId){
        CrawlerUserToken info = null;
        try {
            String vStr = EncryptUtils.simpleDecode(tenantId);
            String[] arr = vStr.split(split);
            info = newInstance();
            info.setCorpCode(arr[0]);
            info.setUserId(arr[1]);
            info.setResumeId(arr[2]);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return info;
    }

    public static String encodeTenantId(String corpCode, Integer userId, Integer resumeId){
        CrawlerUserToken info = newInstance();
        info.setCorpCode(corpCode);
        info.setUserId(userId.toString());
        info.setResumeId(resumeId.toString());
        return EncryptUtils.simpleEncode(info.toTenantIdString());
    }


    public static CrawlerUserToken newInstance(){
        return new CrawlerUserToken();
    }

    public String getCorpCode() {
        return corpCode;
    }

    public void setCorpCode(String corpCode) {
        this.corpCode = corpCode;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getResumeId() {
        return resumeId;
    }

    public void setResumeId(String resumeId) {
        this.resumeId = resumeId;
    }

    public String toTenantIdString() {
        return corpCode + split + userId + split + resumeId;
    }
}
